package org.infodavid.common.persistence.impl;

import java.util.HashMap;
import java.util.Map;

import org.infodavid.common.persistence.IConnectionConfiguration;

/**
 * The Class ConnectionConfigurationImpl.
 */
public class ConnectionConfigurationImpl implements IConnectionConfiguration {

	/** serialVersionUID. */
	private static final long serialVersionUID = -6474625515242390306L;

	/** The properties. */
	private Map<String,String> properties = new HashMap<String,String>();

	/** The hostname. */
	private String host = null;

	/** The name. */
	private String name = null;

	/** The type. */
	private String type = null;

	/** The driver. */
	private String jdbcDriver = null;

	/** The JNDI name. */
	private String jndiName = null;

	/** The user password. */
	private String password = null;

	/** The user name. */
	private String user = null;

	/** The connection string. */
	private String stdConnectionString = null;

	/** The schema. */
	private String schema = null;

	/** The TCP port. */
	private Integer tcpPort = null;

	/**
	 * constructor.
	 */
	public ConnectionConfigurationImpl() {
		super();
	}

	/**
	 * constructor.
	 * @param conf the source configuration
	 */
	public ConnectionConfigurationImpl(final IConnectionConfiguration conf) {
		this();

		setHost(conf.getHost());
		setTcpPort(conf.getTcpPort());
		setJdbcDriver(conf.getJdbcDriver());
		setJndiName(conf.getJndiName());
		setName(conf.getName());
		setPassword(conf.getPassword());
		setProperties(conf.getProperties());
		setSchema(conf.getSchema());
		setStdConnectionString(conf.getStdConnectionString());
		setType(conf.getType());
		setUser(conf.getUser());
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#getHost()
	 */
	public String getHost() {
		return host;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#getJdbcDriver()
	 */
	public String getJdbcDriver() {
		return jdbcDriver;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#getName()
	 */
	public String getName() {
		return name;
	}

	/**
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#getType()
	 */
	public String getType() {
		return type;
	}

	/**
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#getTcpPort()
	 */
	public Integer getTcpPort() {
		return tcpPort;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#getJndiName()
	 */
	public String getJndiName() {
		return jndiName;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#getPassword()
	 */
	public String getPassword() {
		return password;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#getSchema()
	 */
	public String getSchema() {
		return schema;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#getStdConnectionString()
	 */
	public String getStdConnectionString() {
		return stdConnectionString;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#getUser()
	 */
	public String getUser() {
		return user;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#setHost(java.lang.String)
	 */
	public void setHost(final String value) {
		host = value;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#setJdbcDriver(java.lang.String)
	 */
	public void setJdbcDriver(final String value) {
		jdbcDriver = value;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#setName(java.lang.String)
	 */
	public void setName(final String value) {
		name = value;
	}

	/**
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#setType(java.lang.String)
	 */
	public void setType(final String value) {
		type = value;
	}

	/**
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#setTcpPort(java.lang.Integer)
	 */
	public void setTcpPort(final Integer value) {
		tcpPort = value;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#setJndiName(java.lang.String)
	 */
	public void setJndiName(final String value) {
		jndiName = value;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#setPassword(java.lang.String)
	 */
	public void setPassword(final String value) {
		password = value;
	}

	public Map<String,String> getProperties() {
		return properties;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#getProperty(java.lang.String)
	 */
	public String getProperty(final String key) {
		return properties.get(key);
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#setProperty(java.lang.String,
	 * java.lang.String)
	 */
	public void setProperty(final String key, final String value) {
		properties.put(key, value);
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#setSchema(java.lang.String)
	 */
	public void setSchema(final String value) {
		schema = value;
	}

	/*
	 * (non-Javadoc)
	 * @see
	 * org.infodavid.common.persistence.IConnectionConfiguration#setStdConnectionString(java.lang.String
	 * )
	 */
	public void setStdConnectionString(final String value) {
		stdConnectionString = value;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IConnectionConfiguration#setUser(java.lang.String)
	 */
	public void setUser(final String value) {
		user = value;
	}

	/**
	 * Sets the properties.
	 * @param values the properties
	 */
	public void setProperties(final Map<String,String> values) {
		properties = values;
	}

	/**
	 * See super class or interface. (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		final StringBuilder builder = new StringBuilder();

		builder.append(super.toString());
		builder.append(" [host=");
		builder.append(host);
		builder.append(", tcpPort=");
		builder.append(tcpPort);
		builder.append(", jdbcDriver=");
		builder.append(jdbcDriver);
		builder.append(", jndiName=");
		builder.append(jndiName);
		builder.append(", name=");
		builder.append(name);
		builder.append(", type=");
		builder.append(type);
		builder.append(", password=");
		builder.append(password);
		builder.append(", properties=");
		builder.append(properties);
		builder.append(", schema=");
		builder.append(schema);
		builder.append(", stdConnectionString=");
		builder.append(stdConnectionString);
		builder.append(", user=");
		builder.append(user);
		builder.append("]");

		return builder.toString();
	}
}
